package chances.wechat.data.ibatis;

public class MySQLDialect implements Dialect {

    protected static final String SQL_END_DELIMITER = ";";

    public String getPageSql(String sql, boolean hasOffset) {
        return DialectSQLHelper.genPageSql(sql, -1, -1);
    }

    public String getPageSql(String sql, int offset, int limit) {
        return DialectSQLHelper.genPageSql(sql, offset, limit);
    }

    public String getCountSql(String sql) {
        String lowSql = sql.toLowerCase();
        int index = lowSql.indexOf("from");
        String countSql = "select count(*) " + sql.substring(index);
        int orderIndex = countSql.indexOf("order by");

        if (orderIndex > 0) {
            countSql.substring(0, orderIndex - 1);
        }
        return countSql;
    }

    public boolean supportsLimit() {
        return true;
    }

}
